// 接口请求
import {
	$http
} from "@escook/request-miniprogram"
import store from "@/store/index.js"

// 全局挂载
uni.$http = $http

$http.baseUrl = 'http://121.5.55.199:12321/oldhome'

$http.beforeRequest = function(config) {
	// 请求头携带token
	const token = store.state.user.token
	if (token) {
		// 为请求头添加身份认证字段
		config.header = {
			// 字段的值可以直接从 vuex 中进行获取
			Authorization: `Bearer ${JSON.parse(token)}`,
		}
	}

	uni.showLoading({
		title: "正在加载中"
	})

	return config
}

$http.afterRequest = () => {
	wx.hideLoading()
}
